// Copyright (C) 2021 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only

import QtQuick
import QtQuick.Controls
import HUAPI_QtQuick_content
import CustomizedComponents
import Qt.labs.settings

Window {
    id: window
    width: 1920
    height: 1280

    visible: true
    title: "HUAPI_QTQUICK"

    // color: "transparent"
    color: "lightgreen"

    // property color themeColor: "transparent"
    property int radius: 20
    flags: Qt.Window | Qt.FramelessWindowHint

    // Login {
    //     radius: window.radius
    // }

    WindowHeadBar {
        id: windowHeadBar

        height: 60

        Rectangle {
            anchors.left: parent.left
            anchors.leftMargin: 20
            anchors.verticalCenter: parent.verticalCenter

            radius: 10
            border.width: 1
            border.color: "lightgray"
            width: parent.height * 1.7
            height: parent.height * 0.8
            color: "transparent"

            Row {
                anchors.fill: parent
                
                SvgBtn {
                    id: lastPageBtn

                    svgSource: "qrc:HUAPI_QtQuick_content/resources/images/svg/SingleLeftArrow.svg"
                    size: parent.height
                    svgScaleFactor: 0
                    enabled: false

                    borderWidth: 0
                }

                SvgBtn {
                    id: nextPageBtn

                    svgSource: "qrc:HUAPI_QtQuick_content/resources/images/svg/SingleRightArrow.svg"
                    size: parent.height
                    svgScaleFactor: 0
                    enabled: false

                    borderWidth: 0
                }
            }
        }

        Row {
            height: parent.height
            anchors.right: parent.right
            spacing: 10
            layoutDirection: Qt.RightToLeft

            HeadBarSvgBtn {
                id: closeBtn
                size: parent.height
                svgSource: "qrc:HUAPI_QtQuick_content/resources/images/svg/CloseIcon.svg"

                PropertyAnimation {
                    id: closeRotateAni
                    target: closeBtn
                    property: 'svgRotation'

                    from: 0
                    to: 90

                    duration: 300
                    easing.type: Easing.InOutQuad
                }

                onIsHoveredChanged: {
                    closeRotateAni.start();
                }

                onClicked: {
                    Qt.quit();
                }
            }

            HeadBarSvgBtn {
                id: maximizedBtn
                size: parent.height
                svgSizeProportion: 0.5

                svgSource: "qrc:HUAPI_QtQuick_content/resources/images/svg/ShowFullScreen.svg"

                onClicked: {
                    if (maximizedBtn.state === "normal") {
                        window.showFullScreen();
                        maximizedBtn.state = "maximized";
                    } else if (maximizedBtn.state === "maximized") {
                        window.showNormal();
                        maximizedBtn.state = "normal";
                    }
                }

                states: [
                    State {
                        name: "normal"
                        PropertyChanges {
                            maximizedBtn.svgSource: "qrc:HUAPI_QtQuick_content/resources/images/svg/ShowFullScreen.svg"
                        }
                    },
                    State {
                        name: "maximized"
                        PropertyChanges {
                            maximizedBtn.svgSource: "qrc:HUAPI_QtQuick_content/resources/images/svg/RestoreWindowSize.svg"
                        }
                    }
                ]

                Component.onCompleted: {
                    maximizedBtn.state = "normal";
                }
            }

            HeadBarSvgBtn {
                id: minimizedBtn
                size: parent.height
                svgSizeProportion: 0.5

                svgSource: "qrc:HUAPI_QtQuick_content/resources/images/svg/ShowMinimized.svg"

                onClicked: {
                    window.showMinimized();
                }
            }
        }
    }

    ResizeArea {
        item: window
    }

    // MouseArea {
    //     anchors.fill: parent
    //     propagateComposedEvents: true
    // }

    // Settings {
    //     id: settings
    //     fileName: "settings.ini"
    //     property color themeColor: "transparent"
    // }

    // Rectangle {
    //     anchors.fill: parent
    //     radius: window.radius
    //     color: "green"
    //     opacity: 0.2
    // }
}
